package com.sdonkey.score.service.impl;


import com.sdonkey.score.bean.LoginReturnBean;

import com.sdonkey.score.dao.ITadvertiserDao;
import com.sdonkey.score.exception.BusinessException;
import com.sdonkey.score.model.AdvertiserBankBean;
import com.sdonkey.score.service.IAccountCentralService;
import com.sdonkey.score.util.ConfigUtil;
import com.sdonkey.score.util.RandomUtil;

import com.sdonkey.score.util.TimeUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

@SuppressWarnings("unused")
@Service("accountCentralService")
public class AccountCentralServiceImpl implements IAccountCentralService {
	
	@Autowired
	private ITadvertiserDao advertiserDao;


   /* *//**
     * 判断邮箱验证码正确性(正确性，有效性)
     *//*
	@Override
	public int checkVerificationCode(String email, String verCode) throws DataAccessException {

		long loseTime = 60000;// 失效时间毫秒值(1分钟)
		// 判断验证码是否失效
		Timestamp str = advertiserDao.loseEmailCode(email, verCode);
		if (str == null) {// 验证码错误
			return 0;
		}
		long millionSeconds = TimeUtil.getMillisOfDate(str);
		long Seconds = millionSeconds + loseTime;
		// 获取当前时间
		Timestamp now = new Timestamp(System.currentTimeMillis());
		long time = TimeUtil.getMillisOfDate(now);
		if (time > Seconds) {// 时间对比 失效 2
			return 2;
		}
		return advertiserDao.checkVerificationCode(email, verCode);
	}
  
	*//**
	 * 更改基本信息
	 *//*
	@Override
	public int updateBasicInfo(LoginReturnBean loginReturnBean) {
		return advertiserDao.updateBasicInfo(loginReturnBean);
	}
    
	*//**
	 * 更改充值金额
	 *//*
	@Override
	 public int updateBalance(String advId,String money,String actualBalance,String totalConsumption) throws DataAccessException {
		if(StringUtils.isBlank(money))money="0";
		if(StringUtils.isBlank(actualBalance))actualBalance="0";
		if(StringUtils.isBlank(totalConsumption))totalConsumption="0";
		Double  balance  = Double.parseDouble(actualBalance) ;
		Double total  = Double.parseDouble(totalConsumption) ;
		Double add = Double.parseDouble(money) ;
		balance = balance + add;
		total=total+add;
		//total = total + add;
		return advertiserDao.updateBalance(advId, add, balance, total);
	}

	@Override
	public int newPassword(String email, String newPassword) throws DataAccessException {
		return advertiserDao.newPassword(email, newPassword);
	}

	@Override
	public int saveCredit(String advId, String credit, String days) throws DataAccessException {
		return advertiserDao.saveCredit(advId, credit, days);
	}


   
	
	*//**
	 * 修改信息的审核状态
	 *//*
	@Override
	public int updateStatus(Map<String,String> map) {
		return advertiserDao.updateStatus(map);
	}

	
	
	@Override
	public boolean existsCredit(String advId) throws DataAccessException {
		return advertiserDao.existsCredit(advId);
	}

	@Override
	public boolean existsEmail(String email) {
		return false;
	}

	@Override
	public void sendValidateCode(String email) throws Exception {
		
	}
	@Override
	public String getTotalConsumption(String attribute) {
		return null;
	}
	@Override
	public int checkNewEmail(String email, String newEmail) {
		
		return advertiserDao.alterEmail(email, newEmail);
	}
	*//**
	 * 提现  修改提现金额字段
	 *//*
	@Override
	public int insertDrawCash(String advId, String money) {
		if(StringUtils.isBlank(money))
			money = "0";
		double num = Double.parseDouble(money);
		return advertiserDao.insertDrawCash(advId, num);
	}*/
	/**
	 * 提现  修改账户余额
	 */
	@Override
	public int updateActualBalance(String advId, String money,String actualBalance) {
		if(StringUtils.isBlank(money)) {
			money = "0";
		}
		if(StringUtils.isBlank(actualBalance)) {
			actualBalance = "0";
		}
		double num = Double.parseDouble(money);
		double balance = Double.parseDouble(actualBalance);
		balance = balance - num;
		return advertiserDao.updateActualBalance(advId, num,balance);
	}

	@Override
	public boolean existsEmail(String email) {
		return false;
	}

	@Override
	public int updateStatus(Map<String, String> map) {
		return 0;
	}

	@Override
	public int updateBalance(String advId, String money, String actualBalance, String totalConsumption) throws BusinessException {
		return 0;
	}

	@Override
	public int newPassword(String email, String newPassword) throws BusinessException {
		return 0;
	}

	@Override
	public int alterEmail(String advId, String email) {
		return 0;
	}

	@Override
	public int saveCredit(String advId, String credit, String days) throws BusinessException {
		return 0;
	}

	@Override
	public boolean existsCredit(String advId) throws BusinessException {
		return false;
	}

	@Override
	public void sendValidateCode(String email) throws Exception {

	}

	@Override
	public int setPayPassword(String advId, String payPwd) {
		return 0;
	}

	@Override
	public int saveBankInfo(AdvertiserBankBean advertiserBankBean) {
		return 0;
	}

	@Override
	public int insertPhoneCode(String advId, String bankPhone, String verCode) {
		return 0;
	}

	@Override
	public int checkPhoneCode(String advId, String bankPhone, String phoneCode) {
		return 0;
	}

	@Override
	public List<AdvertiserBankBean> getBankInfo(String advId) {
		return null;
	}

	@Override
	public String totalSpending(String advId) {
		return null;
	}

	@Override
	public double getAdvertiserBalance(String advId) {
		return 0;
	}

	@Override
	public int checkName(String memberName) {
		return 0;
	}

	@Override
	public void sendEmailVerCode(HttpSession session, String email) {

	}

	@Override
	public void saveRecharge(String advId, String money) {

	}

	@Override
	public int companyName(String companyName) {
		return 0;
	}
	/**
	 * 更改邮箱
	 *//*
	@Override
	public int alterEmail(String advId, String email) {
		return advertiserDao.alterEmail(advId, email);
	}
	
	*//**
	 * 设置微积分支付密码
	 *//*
	@Override
	public int setPayPassword(String advId, String payPwd) {
		return advertiserDao.setPayPassword(advId, payPwd);
	}


	*//**
	 * 保存用户绑定的银行卡信息
	 *//*
	@Override
	public int saveBankInfo(AdvertiserBankBean advertiserBankBean) {
		
		return advertiserDao.saveBankInfo(advertiserBankBean);
	}
	*//**
	 * 保存手机验证码
	 *//*
	@Override
	public int insertPhoneCode(String advId, String bankPhone, String verCode) {
		return advertiserDao.insertPhoneCode(advId,bankPhone,verCode);
	}
	*//**
	 * 判断手机验证码正确性(正确性，有效性)
	 *//*
	@Override
	public int checkPhoneCode(String advId, String bankPhone, String phoneCode) {

		long loseTime = 300000;// 失效时间毫秒值(5分钟)
		// 判断验证码是否失效
		Timestamp str = advertiserDao.losePhoneCode(advId, bankPhone, phoneCode);
		if (str == null) {// 验证码错误
			return 0;
		}
		long millionSeconds = TimeUtil.getMillisOfDate(str);
		long Seconds = millionSeconds + loseTime; // 加上失效时间
		// 获取当前时间
		Timestamp now = new Timestamp(System.currentTimeMillis());
		long time = TimeUtil.getMillisOfDate(now);
		if (time > Seconds) {// 时间对比 失效 2
			return 2;
		}
		return advertiserDao.checkPhoneCode(advId, bankPhone, phoneCode);
	}
	*//**
	 * 获取银行卡信息
	 *//*
	@Override
	public List<AdvertiserBankBean> getBankInfo(String advId) {
		
		return advertiserDao.getBankInfo(advId);
	}
	
	*//**
	 * 累计总支出
	 *//*
	@Override
	public String totalSpending(String advId) {
		
		return advertiserDao.totalSpending(advId);
	}
	*//**
	 * 获取当前广告余额
	 *//*
	@Override
	public double getAdvertiserBalance(String advId) {
		return advertiserDao.getAdvertiserBalance(advId);
	}
	*//**
	 * 修改后的会员昵称去重
	 *//*
	@Override
	public int checkName(String memberName) {
		return advertiserDao.getName(memberName);
	}
	
	*//**
	 * 向邮箱发送验证码
	 *//*
	@Override
	public void sendEmailVerCode(HttpSession session, String email) {
		// 发送验证码至邮箱
		String verCode = RandomUtil.random(6);

		StringBuilder sb = new StringBuilder();
		sb.append("<p>尊敬的用户【" + email + "】您好！<br /><br />此邮件旨在验证邮箱。" + "此次您的验证码为【" + verCode
				+ "】,请您登录后尽快修改。<br />此为系统邮件，请勿回复。如有任何疑问或遇到问题，请发送电子邮件至 xiaomaolv@jifenguanggao.com获取我们的帮助。<br />感谢您对积分平台的支持。<br /><br />积分平台 支持中心</p>");
		try {
			if (ConfigUtil.getString("sendMail") != "" && !(ConfigUtil.getString("sendMail").isEmpty())) {
				SendMailNew.sendMailAsText1("小毛驴  邮箱验证", ConfigUtil.getString("sendMail"), email, sb.toString());
				String advId = (String) session.getAttribute("advId");
				//保存邮箱和验证码
				advertiserDao.insertVerificationcode(advId, email, verCode);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	*//**
	 * 保存充值金额
	 *//*
	@Override
	public void saveRecharge(String advId, String money) {
		advertiserDao.saveRecharge(advId,money);
	}

	*//**
	 * 公司名称唯一校验
	 *//*
	@Override
	public int companyName(String companyName) {
		return advertiserDao.getCompanyName(companyName);
	}*/


}
